<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>发送请求</button>
    <script>
        let btn = document.querySelector('button');
        let xhr = null;
        // 用isSending来标记当前是否正在发送请求
        let isSending = false;
        btn.onclick = function(){
            // 如果正在发送，则终止之前发送的请求
            if (isSending) xhr.abort();
            xhr = new XMLHttpRequest();
            isSending = true;
            xhr.open('POST', 'http://127.0.0.1:8000/del');
            xhr.send(); 
            xhr.onreadystatechange = function(){
                if (xhr.readyState === 4){
                    isSending = false;
                }
            };
        };
    </script>
</body>
</html>